import {
    BuildingConfigs,
    BuildingUpgradeConfigs,
} from "db://assets/proto/shared/v1/configs";
import {GlobalConfigsLoader} from "db://assets/script/global-configs-loader";
import Long from "long";
import {cmm} from "db://assets/script/utils/cmm";

export class BuildingConfigsLoader {

    findBuildingUpgradeConfigsByLevel(buildingId: Long, level: number): BuildingUpgradeConfigs | undefined {
        const blc = GlobalConfigsLoader.instance.getBuildingUpgradeConfigs()
        const uk = buildingId.toString() + '-' + level.toString()
        return blc.get(uk)
    }

    findBuildingConfigs(buildingId: Long): BuildingConfigs | undefined {
        const bc = GlobalConfigsLoader.instance.getBuildingConfigs()
        return bc.get(buildingId.toString())
    }

    findCanBuildBuildingConfigs(): BuildingConfigs[] {
        const bc = GlobalConfigsLoader.instance.getBuildingConfigs()
        return cmm.map2array(bc, (k, v) => v).filter(c => c.canBuild)
    }
}

export const buildingConfigsLoader = new BuildingConfigsLoader();